<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB, Session;

class OrderController extends Controller
{
    /**
     * Display a listing of the resource.
     * 订单页面
     * @return \Illuminate\Http\Response
     */
    public function order(Request $request)
    {
        $keyword = $request->get("keyword", '');
        $orders = DB::table("order")
                ->where("order_status", 1)
                ->orderBy("id", "desc")
                ->where("order_name", "LIKE" , "%".$keyword."%")
                ->paginate(10);
        return view("admin.order.order", compact("orders", "keyword", "s"));
    }

    /*
     * 查看订单详情 detail
     */
    public function detail($id)
    {
        $order =  DB::table("order")
                ->where("id" ,$id)
                ->first();
        $shop = DB::table("order_details")->where('order_number', $order->order_number)
            ->get();
        foreach($shop as $s){
            $s->goods_thumb = DB::table('goods')->where('id', $s->goods_id)->pluck('goods_thumb');
        }
        return view("admin.order.xiugai", compact("order", "shop", "s", "a"));
    }
    /*
     * status 修改发货
     */
    public function status($id)
    {
        DB::table("order_details")->where("id", $id)->update(["order_status"=> 2]);
        return back();
    }
    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }

    /**
     * Display the specified resource.
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function edit(Request $request,$id)
    {
//        // 获取数据
//        $data = ($request->except("_token"));
////        dd($data);
//        // 验证可有可无
//        // 修改数据库
//        if (!$request->addr_county)
//        {
//            $data['addr_county'] = "";
//        }
//        DB::table("user_address")->where("id", $id)->update($data);
//        return redirect("/admin/order/xiugai/{id}");
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request $request
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        //
    }
}